package ade.prime.model;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Représente l'historique d'un cours, c'est-à-dire les valeurs d'un cours
 * avant se dernière mise à jour.
 * 
 * @author		Schnell Michaël, Zanette Sébastien
 * @version		1.0
 */
public class LessonHistory implements Parcelable {
	
	private static final String PRINT_FORMAT = 
			"ID: %d\nSalle: %s\nHeure: %s" ; //$NON-NLS-1$
	
	protected long id ;

	protected String rooms ;
	
	protected String time ;
	
	/**
	 * 
	 */
	public LessonHistory() {
		super() ;
	}// LessonHistory()
	
	/**
	 * @param id
	 * @param rooms
	 * @param time
	 */
	public LessonHistory(long id, String rooms, String time) {
		this() ;
		this.id = id;
		this.rooms = rooms;
		this.time = time;
	}// LessonHistory(long, String, String)
	
	/**
	 * 
	 * @param source
	 */
	public LessonHistory(Parcel source) {
		this(source.readLong(), source.readString(), source.readString()) ;
	}// LessonHistory(Parcel)
	
	public LessonHistory(Lesson oldLesson) {
		this(oldLesson.getLessonId(), oldLesson.getRoom(), oldLesson.getTime()) ;
	}// LessonHistory(Lesson)

	public long getId() {
		return this.id ;
	}// getId()

	public void setId(long id) {
		this.id = id ;
	}// setId(long)

	public String getRooms() {
		return this.rooms ;
	}// getRooms()

	public void setRooms(String rooms) {
		this.rooms = rooms ;
	}// setRooms(String)

	public String getTime() {
		return this.time ;
	}// getTime()

	public void setTime(String time) {
		this.time = time ;
	}// setTime(String)
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean equals(Object o) {
		if (o instanceof LessonHistory) {
			LessonHistory other = (LessonHistory) o ;
			return (this.id == other.id) && this.rooms.equals(other.rooms)
					&& this.time.equals(other.time) ;
		}// if
		return super.equals(o) ;
	}// equals(Object)
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public int hashCode() {
		return this.time.hashCode() ;
	}// hashCode()

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String toString() {
		return String.format(PRINT_FORMAT, 
				Long.valueOf(this.id), 
				this.rooms,
				this.time) ;
	}// toString()
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public int describeContents() {
		return 0 ;
	}// describeContents()
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeLong(this.id) ;
		dest.writeString(this.rooms) ;
		dest.writeString(this.time) ;
	}// writeToParcel(Parcel, int)
	
	public static final Parcelable.Creator<LessonHistory> CREATOR =
			new Creator<LessonHistory>() {
		/**
		 * {@inheritDoc}
		 */
		@Override
		public LessonHistory createFromParcel(Parcel source) {
			return new LessonHistory(source) ;
		}// createFromParcel(Parcel)
		/**
		 * {@inheritDoc}
		 */
		@Override
		public LessonHistory[] newArray(int size) {
			return new LessonHistory[size] ;
		}// newArray(int
	} ;
	
}// class LessonHistory